package edu.hit.crawler.mapred;

import java.net.URL;

import org.apache.hadoop.io.FloatWritable;
import org.apache.hadoop.mapreduce.Partitioner;

import edu.hit.crawler.io.CrawItem;

public class HostPartitioner extends Partitioner<FloatWritable, CrawItem> {


	
	@Override
	public int getPartition(FloatWritable key, CrawItem value, int numPartitions) {
		try {
			
			int hashCode = new URL(value.getUrl()).getHost().hashCode();
			return (hashCode & Integer.MAX_VALUE) % numPartitions;
			
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
		return 0;
	}
	
}
